

//注册页面
require(['./config'],()=>{
    require(['jquery'],()=>{
        $('header').load('/html/header.html',()=>{
            require(['header'],(modA)=>{
              modA()
            })
          })
        $('footer').load('/html/footer.html')
    })
    require([],()=>{
        let btn=document.querySelector('.btn')
        let username =document.querySelector('.username')
        let password =document.querySelector('.password')
        let passwords =document.querySelector('.passwords')
        let phone=document.querySelector('.phone')
        //账号正则验证
        function zh(){
            if(username.value==''){
                username.parentNode.nextSibling.innerHTML='请输入账号'
            }else{
                let reg = /^\d{9}$/
                if (reg.test(username.value) == true) {
                    username.parentNode.nextSibling.innerHTML='' //验证成功返回一个值下面做判定是否提交
                    return 1
                } else {
                    username.parentNode.nextSibling.innerText = '账号由9位数字构成'
                }
            }
        }


        username.onblur = function () {
            zh()
        }
        //密码正则验证
        function mima(){
            if(password.value==''){
                password.parentNode.nextSibling.innerText ='请输入密码'
            }else{
                let reg = /^[a-z]\d{4,16}$/
                if(reg.test(password.value) == true){
                    password.parentNode.nextSibling.innerText=''
                    return 1
                }else{
                    password.parentNode.nextSibling.innerText='密码不符合'
                }
            }
            
        }
        password.onblur = function () {
            mima()
        }

        //验证密码正则
        function mimas(){
            if(passwords.value==''){
                passwords.parentNode.nextSibling.innerText ='请输入密码'
            }else{
                if(passwords.value==password.value){
                    passwords.parentNode.nextSibling.innerText=''
                    return 1
                }else{
                    passwords.parentNode.nextSibling.innerText='密码不符合'
                }
            }
        }
        passwords.onblur=function(){
            mimas()
        }

        //手机号验证
        function Phone(){
            if(phone.value==''){
                phone.parentNode.nextSibling.innerHTML='请输入手机号码'
            }else{
                let reg = /^\d{11}$/
                if (reg.test(phone.value) == true) {
                    phone.parentNode.nextSibling.innerHTML='' //验证成功返回一个值下面做判定是否提交
                    return 1
                } else {
                    phone.parentNode.nextSibling.innerText = '由11位数字构成'
                }
            }
        }
        phone.onblur = function () {
            Phone()
        }
        btn.onclick=(e)=>{
            zh()
            mima()
            Phone()
            e = e || window.event
            if (zh() == 1 && mima() == 1 && Phone() ==1) {
                console.log(123)
                let name = username.value
                let mima = password.value
                let sj =phone.value
                let obj = {
                    name: name,
                    mima: mima,
                    sj : sj
                }
                let str = localStorage.getItem('yonghu')
                let arr = JSON.parse(str) || []
                arr.push(obj)
        
                localStorage.setItem('yonghu', JSON.stringify(arr))
                alert('注册成功')
                location.href = `http://localhost:2202/index.html`
                
            }
            return false
        }
    })
})